#ifndef OCTREE_H
#define OCTREE_H

#include <windows.h>
#include "gl\gl.h"
#include "frustum.h"
#include "vector.h"
#include <math.h>
#include <vector>
using namespace std;


// These values (0 - 7) store the index ID's for the octree node array (m_pOctreeNodes)
enum eOctreeNodes
{
	TOP_LEFT_FRONT,			// 0
	TOP_LEFT_BACK,			// 1
	TOP_RIGHT_BACK,			// etc...
	TOP_RIGHT_FRONT,
	BOTTOM_LEFT_FRONT,
	BOTTOM_LEFT_BACK,
	BOTTOM_RIGHT_BACK,
	BOTTOM_RIGHT_FRONT
};

// This is our debug lines class to view the octree visually
class CDebug 
{
	public:
		void AddDebugLine(Vector vPoint1, Vector vPoint2);
		void AddDebugRectangle(Vector vCenter, float width, float height, float depth);
		void RenderDebugLines();
		void Clear();			

	private:
		
};

class COctree
{
public:
	COctree();
	~COctree();
	Vector GetCenter() {	 return m_vCenter;	}
	int GetTriangleCount()  {   return m_TriangleCount;	}
	float GetWidth() {	 return nodeWidth;	}
	bool IsSubDivided()  {   return m_bSubDivided;	}
	void GetSceneDimensions(Vector *pVertices, int numberOfVerts);
	Vector GetNewNodeCenter(Vector vCenter, float width, int nodeID);
	void CreateNode(Vector *pVertices, Vector *pNormals, int numberOfVerts, Vector vCenter, float width);
	void CreateNewNode(Vector *pVertices, Vector *pNormals,	vector<bool> pList, int numberOfVerts,
				  	   Vector vCenter,	float width,        int triangleCount, int nodeID);
	void AssignVerticesToNode(Vector *pVertices, Vector *pNormals, int numberOfVerts);
	void DrawOctree(COctree *pNode);
	void DestroyOctree();

private:
	CDebug g_Debug;

	int g_MaxSubdivisions;
	int g_MaxTriangles;
	int g_EndNodeCount;
	bool g_bLighting;
	bool g_bRenderMode;
	void InitOctree();
	bool m_bSubDivided;
	float nodeWidth;
	int m_TriangleCount;
	Vector m_vCenter;
	Vector *m_pVertices;
	Vector *m_pNormals;
	COctree *m_pOctreeNodes[8];	
};

#endif /*OCTREE_H*/